<?php

header("Content-type:text/html;charset=utf-8");

$typeId=$_GET["typen"];
$conn = mysql_connect("localhost","root","root");
mysql_select_db("2017");
$sqlstr ='select * from xqy where typen="'.$typeId.'"';      

$result = mysql_query($sqlstr,$conn);//执行查询的sql语句后，有返回值，返回的是查询结果
if(!$result){
die("获取数据失败".mysql_error());
}

//查询列数
$query_cols = mysql_num_fields($result);
//echo "列数：".$query_cols;
//查询行数
$query_num =mysql_num_rows($result);
//echo "行数：".$query_num;

$str="[";

$query_row = mysql_fetch_array($result);//游标下移,拿出结果集中的某一行，返回值是拿到的行；
while($query_row){
$str = $str.'{ "Id":"'.$query_row[0].'","word":"'.$query_row[1].'"
,"machine":"'.$query_row[2].'","pp":"'.$query_row[3].'"
,"xm":"'.$query_row[4].'","jiage":"'.$query_row[5].'"
}';



$query_row = mysql_fetch_array($result);
if($query_row){
$str = $str.",";
}
}
$str = $str."]";
//4、关闭数据库
mysql_close($conn);

//3、给客户端返回商品的json数组！
echo $str;

?>